import Mock from 'mockjs'

function getList() {
  const json = {code: 200, success: true, msg: '操作成功'};
  const list = [];
  list.push(
    {
      id: '1',
      name: '数据迁移B-D',
      cron: '2,5 * * * * ? ',
      entryPoint: 'mian.kjb',
      status: 0
    },
    {
      id: '2',
      name: '数据迁移A-B',
      cron: '1-2 * * * * ?',
      entryPoint: 'mian.kjb',
      status: 1
    },
  );
  json.data = {
    total: 2,
    size: 10,
    current: 1,
    searchCount: true,
    pages: 1,
    records: list,
  };
  return json;
}

function getDetail() {
  const json = {code: 200, success: true, msg: '操作成功'};
  let detail = {
    id: '1',
    name: '数据迁移B-D',
    cron: '2,5 * * * * ? ',
    entryPoint: 'mian.kjb',
    status: '启动',
  };
  json.data = detail;
  return json;
}

export default ({mock}) => {
  if (!mock) return;
  Mock.mock('/api/kettle/task/list', 'get', () => {
    return getList();
  })
  Mock.mock(/\/api\/kettle\/task\/\d+/, 'get', () => {
    return getDetail();
  })
}
